package com.aimei520.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonResult {

	private boolean success;
	private String msg;
	
	public JsonResult() {
		
	}
	
	public JsonResult(boolean success, String msg) {
		this.success = success;
		this.msg = msg;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	@Override
	public String toString() {
		return "JsonResult [success=" + success + ", msg=" + msg + "]";
	}
	
	public String toJson() {
		String result = "";
		try {
			result += new ObjectMapper().writeValueAsString(this);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
			result +="{'success':false}";
		}
		return result;
	}
}
